package com.zdkj.subway.support.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.util.R;
import com.zdkj.common.data.mybatis.wrapper.CustomQueryWrapper;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.support.dto.in.SwParamTicketPriceDTO;
import com.zdkj.subway.support.entity.SwParamTicketPrice;
import com.zdkj.subway.support.service.SwParamTicketPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 票价设置表
 *
 * @author cui_com
 * @date 2020-01-08 17:20:38
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swparamticketprice")
@Api(value = "swparamticketprice", tags = "票价设置表管理")
public class SwParamTicketPriceController {

    private final SwParamTicketPriceService swParamTicketPriceService;

    /**
     * 详细分页查询
     *
     * @param page               分页对象
     * @param swParamTicketPriceDTO 票价设置表
     * @return
     */
    @ApiOperation(value = "详细分页查询", notes = "详细分页查询")
    @GetMapping("/detail/page")
    public R getSwParamTicketPriceDetailPage(Page page, SwParamTicketPriceDTO swParamTicketPriceDTO) {
        return R.ok(swParamTicketPriceService.queryDetailByPage(
                page, new CustomQueryWrapper(SwParamTicketPrice.class)
                        .addDTO(swParamTicketPriceDTO)
                        .init()));
    }

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param swParamTicketPrice 票价设置表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public R getSwParamTicketPricePage(Page page, SwParamTicketPrice swParamTicketPrice) {
        return R.ok(swParamTicketPriceService.page(page, Wrappers.query(swParamTicketPrice)));
    }


    /**
     * 通过id查询票价设置表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swParamTicketPriceService.getById(id));
    }

    /**
     * 新增票价设置表
     *
     * @param swParamTicketPrice 票价设置表
     * @return R
     */
    @ApiOperation(value = "新增票价设置表", notes = "新增票价设置表")
    @SysLog("新增票价设置表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_add')")
    public R save(@RequestBody SwParamTicketPriceDTO swParamTicketPrice) {
        SwParamTicketPrice defaultObj = ObjectUtils.getDefaultObj(SwParamTicketPrice.class);
        BeanUtils.copyProperties(swParamTicketPrice, defaultObj);
        return R.ok(swParamTicketPriceService.save(defaultObj));
    }

    /**
     * 修改票价设置表
     *
     * @param swParamTicketPrice 票价设置表
     * @return R
     */
    @ApiOperation(value = "修改票价设置表", notes = "修改票价设置表")
    @SysLog("修改票价设置表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_edit')")
    public R updateById(@RequestBody SwParamTicketPriceDTO swParamTicketPrice) {
        SwParamTicketPrice obj = new SwParamTicketPrice();
        BeanUtils.copyProperties(swParamTicketPrice, obj);
        return R.ok(swParamTicketPriceService.updateById(obj));
    }

    /**
     * 通过id删除票价设置表
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除票价设置表", notes = "通过id删除票价设置表")
    @SysLog("通过id删除票价设置表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('support_sw_param_ticket_price_del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(swParamTicketPriceService.removeById(id));
    }

}
